//
//  ContactManager.m
//  04_集合2
//
//  Created by dllo on 16/7/7.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "ContactManager.h"

@implementation ContactManager
// 初始化
- (instancetype)initWithDic:(NSMutableDictionary *)dic {
    self = [super init];
    if (self) {
        _contactDictionary = dic;
    }
    return self;
}

// 添加
- (void)addContact:(Contact *)contact {
    if (contact.name.length > 0 && contact.phoneNumber.length > 0) {
        NSMutableArray *contacArr = [self.contactDictionary objectForKey:contact.groupName];
        if (contacArr == nil) {
            contacArr = [NSMutableArray arrayWithObject:contact];
            [self.contactDictionary setObject:contacArr forKey:contact.groupName];
        } else {
            [contacArr addObject:contact];
            [self.contactDictionary setObject:contacArr forKey:contact.groupName];
        }
        NSLog(@"添加联系人%@成功", contact.name);
    } else {
        NSLog(@"添加联系人%@失败", contact.name);
    }
}

// 删除
- (void)delContact:(Contact *)contact {
    [self.contactDictionary removeObjectForKey:contact];
}

// 删除分组
- (void)delGroupContact:(NSString *)group {
    [self.contactDictionary removeObjectForKey:group];
}

@end
